
<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
if(isset($_SESSION['lang']))
    require_once "./language_files/sendToOrg_" . $_SESSION['lang'] . ".php";
else
    require_once "./language_files/sendToOrg_en.php";

require_once "functions.php";
$currentConfID='$_SESSION ["conference_id"]'; // need to actovate session
function sendRequest($requestUserID,$request,$conference_id)// I will take them from the session that has been chosen in the checklist
{
    global $lang;
    $email='marouchiha@gmail.com'; //for testing the code
    $email='$_SESSION["email"]'; // need to activate the session
    $currentConfID='$_SESSION ["conference_id"]'; // need to actovate session
    $i=0; //set counter by zero
    $request=mysql_real_escape_string($_POST['invitation']); //set request value by submit invitation
    while($row['member_id2'])
    {
        $currentUserID=mysqli_query($check,"SELECT member_id FROM Member WHERE email='" . $email . "'") //select the id from table member when the email enterd is the same as the email in the database to be get the id for the current user
                or die(mysql_error()); //returns the error description of the last MySQL operation
        $row=mysqli_fetch_assoc($currentUserID); //return value of current user in an array from the querey if it is true
        $currentUserID=$row['member_id']; //set current user id to the id f=that we got from the querey
        $O='O';
        $getMembers=mysqli_query($check,"SELECT member_id2 FROM member_request_member WHERE Approve IS NULL") or die(mysql_error()); //get the id of the second member which is the reciver from table member_request_member when the aproval is not accepted yet

        $requestUserID=$row[$i];
        mysqli_query($check,"UPDATE member_request_member SET request= $request where member_id2 = $row ['$currentUserID'] 
	and conference_id= $currentConfID and type = $O") // update table member_request_member that the request sent to be the rquest in database and member 2 will be current member
                or die(mysql_error());//returns the error description of the last MySQL operation
        $i++;
    }
    $subject=$lang['request'];
    $message=<<<EMAIL
The Confo site asks you to become a member in the review committe.
Please review this request in the requests section on your account for more details.

Thank you.
EMAIL;
    $from='omar.kahil@gmail.com';
    $headers=$lang['from'] . $from;
    mail($getMembers,$subject,$message,$headers);

    // email form sent to member 2
}
if(isset($_POST['send']))
{
    sendRequest($row[$requestUserID],$request,$currentConfID);
}

//if send button clicked the request will be sentwith request user ID and the invitation and the id of the conf that the organizer asked him to be organizer at it
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <title><?php echo $lang['invite'];?></title>
    </head>
    <form method="post" action="sendToOrg.php">   
        <textarea name="invitation" value ="" cols="80" rows="20">
            <?php echo $lang['message'];?>
        </textarea><br/>
        <tr><td><input type="submit" name="send" value="<?php echo $lang['send'];?>"></td></tr>
        <br/>
    </form>
</html>